$(document).ready(function(e) {

	$('#select_all').live('click', function(e) {
		
		var checked = $(this).attr('checked');
		
		$('.select_article').each(function(e) {
			$(this).attr('checked', checked);
		});
		
	});
	
	$('.switch_status').live('click', function(e) {
		
		var elt = $(this);
		
		$.ajax({
			dataType: 'json',
			url: elt.attr('href'),
			success: function(e) {
				if(e.result) {
					elt.attr('href', e.href);
					elt.children('img').attr('src', e.src);
				
				} else {
				
					$('#manage_message').html('<div class="error">'+e.message+'</div>');
					$('#manage_message').show();
					setTimeout("$('#manage_message').fadeOut()", 2000);
			
				}
				
				return false;
			},
			error: function(e) {
				alert(e);
				
				return false;
			}
		});
		
		return false;
	
	});
	
	$('.delete').live('click', function(e) {
		
		if(confirm('Voulez-vous vraiment supprimer cet article ?')) {
			var elt = $(this);
		
			$.ajax({
				dataType: 'json',
				url: elt.attr('href'),
				success: function(e) {
					if(e.result) {
						
						elt.parent().parent().remove();
				
						$('#manage_message').html('<div class="information">'+e.message+'</div>');
						$('#manage_message').show();
						setTimeout("$('#manage_message').fadeOut()", 2000);
				
					} else {
				
						$('#manage_message').html('<div class="error">'+e.message+'</div>');
						$('#manage_message').show();
						setTimeout("$('#manage_message').fadeOut()", 2000);
			
					}
				
					return false;
				},
				error: function(e) {
					alert(e);
				
					return false;
				}
			});
		
			return false;
		}
		
		return false;
	});

});
